package com.wnxy.controller;

import com.wnxy.pojo.Goods;
import com.wnxy.service.GoodsService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

@RestController
@Api(tags = "商品管理")
public class GoodsController {

    @Autowired
    private GoodsService goodsService;

    /**
     * 接口1：根据关键字爬取JD数据
     * @param keyword
     * @return
     */
    @GetMapping("/parse/{keyword}")
    @ApiOperation("爬取数据")
    public Boolean parseJd(@PathVariable("keyword") String keyword) throws Exception {
        goodsService.parseJd(keyword);
        return true;
    }

    /**
     * 接口2： http://localhost:8080/goods/java/1/20
     * @param keyword 搜索的关键字
     * @param pageNum 当前页
     * @param pageSize 页大小
     * @return
     */
    @GetMapping("/goods/{keyword}/{pageNum}/{pageSize}")
    @ApiOperation("搜索索引库")
    public List<Goods> search(
            @PathVariable("keyword") String keyword,
            @PathVariable("pageNum") Integer pageNum,
            @PathVariable("pageSize") Integer pageSize) {
        return goodsService.search(keyword,pageNum,pageSize);
    }

}
